<template>
	<view>
		<z-paging :fixed="true" ref="paging" v-model="dataList" @query="queryList">
			<view :style="{height: height + 'px'}" slot="top"></view>
			<!-- 词库列表 -->
			<view class="book">
				<view class="book-box">
					<view class="book-box-item d-s-c border-b-e"  v-for="(item, index) in dataList" :key="index">
						<view class="book-box-item_image">
							<image :src="item.book_img" mode=""></image>
						</view>
						<view class="ml20 mr20 f-1">
							<view class="f30 fb gray3 mb10">{{item.book_name}}</view>
							<view class="f22 gray6">单词数量{{item.total_word_num}}个,已选{{item.study_word_num}}个,剩余{{sub(item.total_word_num, item.study_word_num)}}个</view>
						</view>
						<view class="book-box-item_button" @click="goPage('/pages/book/exam?bookId='+item.book_id)" v-if="item.total_word_num==item.study_word_num">过关检测</view>
					</view>
				</view>
			</view>
		</z-paging>
	</view>
</template>

<script>
	export default {
		props: {
			height: {
				type: [Number, String],
				default: 0
			}
		},
		data() {
			return {
				dataList: []
			}
		},
		computed: {
			sub(val1, val2) {
				return (val1, val2) => {
					return Number(val1) - Number(val2)
				}
			},
		},
		methods: {
			// 获取教材列表
			queryList(pageNo, pageSize) {
				this.$u.post(this.$u.api.userBookList, {
					pageNo: pageNo,
					pageSize: pageSize,
				}).then((res) => {
					if (res.code == 1) {
						this.$refs.paging.complete(res.data.data)
					} else {
						this.$refs.paging.complete(false)
					}
				}).catch((err) => {
					this.$refs.paging.complete(false)
				})
			},
			goPage(page) {
				if (page) {
					uni.navigateTo({
						url: page,
					})
				}
			},
		}
	}
</script>

<style lang="less" scoped>
	page {
		background-color: #F8F8F8;
	}
	
	.book {
		width: 100%;
		padding: 30rpx;
		box-sizing: border-box;
	}
	.book-box {
		width: 100%;
		background: #FFFFFF;
		border-radius: 20rpx;
		box-sizing: border-box;
	}
	.book-box-item{
		padding: 30rpx 0;
		margin: 0 30rpx;
		&:hover{
			background-color: rgba(11,153,254,0.5);
			border-radius: 20rpx;
			cursor: pointer;
		}
		
		.book-box-item_image {
			width: 72rpx;
			height: 96rpx;
			
			image {
				display: block;
				width: 72rpx;
				height: 96rpx;
			}
		}
		
		.book-box-item_button{
			width: 140rpx;
			height: 50rpx;
			background: linear-gradient(180deg, #1F93FF, #387BEF);
			border-radius: 10rpx;
			color: #FFFFFF;
			text-align: center;
			line-height: 50rpx;
			font-size: 24rpx;
		}
		
	}
</style>
